Ninja Database Pro
Loading Records
Basic Tasks > Loading Records

Records can be loaded by primary key, by index, or by a LINQ expression.  All records for a table can be loaded.  This is useful for lookups.  When loading a single record, or when items match the LINQ expression, any child or parent records are automatically loaded.  For example, when an Order object is loaded it will automatically load the child OrderDetails.  Object queries perform a table scan and are the slowest way to load records.  Index Queries will only load records that match the index value and are much faster.

 

C# Example

 

//**** Load by primary key

Person person = db.Load<Person>(123);

 

//**** Load All Persons

List<Person> persons = db.LoadAll<Person>();

 

//**** Load by LINQ

//Create a person object query

ObjectQuery<Person> query = db.CreateObjectQuery<Person>();

 

//Create a LINQ expression

var result = from p in query

                                                 where p.Name == "Jane"

                                                 select p;

 

//Update each Jane to Jane Smith

foreach (Person item in result)

{

                item.Name = "Jane Smith";

                db.Save(item);

}

 

//**** Load by index

var gregQuery = db.CreateIndexQuery<Person,string>("Name").Where(o => o.Index == "Greg");

 

foreach (var person in gregQuery)

{

                Console.WriteLine(person.LazyValue.PersonId);

}